
const AppRun=qguan("appRun" );
let inBrowser = typeof window !== 'undefined'
const  JsrLoad = qguan(0,"JsrLoad.js")
const  ApplicationContext = qguan(0,"ApplicationContext.js")
const  AopContext = qguan(0,"AopContext.js")
const  Aop = qguan(0,"Aop.js")
const  Service = qguan(0,"Service.js")
const  Resource = qguan(0,"Resource.js")
const  AopFactory = qguan(0,"AopFactory.js")


const  WebRoot = qguan(0,"WebRoot.js")
const  NodeRoot = qguan(0,"NodeRoot.js")
const  RunApplication = qguan(0,"RunApplication.js")
const  ClassLoad = qguan(0,"ClassLoad.js")
const  FuncLoad = qguan(0,"FuncLoad.js")
const  StrTo = qguan(0,"StrTo.js")
const  Phere = qguan(0,"Phere.js")
const  RunJsr = qguan(0,"RunJsr.js")
const  RunContext = qguan(0,"RunContext.js")
const  RunEntity = qguan(0,"RunEntity.js")
const  Synchro = qguan(0,"Synchro.js")
const  SyncJsLoad = qguan(0,"SyncJsLoad.js")
const  DefaultLoad = qguan(0,"DefaultLoad.js")
const  Preloading = qguan(0,"Preloading.js")

const Block =qguan(0,"Block.js")
const Row =qguan(0,"Row.js")
const Dx =qguan(0,"Dx.js")

const Rx =qguan(0,"Rx.js")
class save{
    constructor(){

    }
    run (a,b,c,d){
        applicationContext.saveBend(a,b,c,d);
    }
}


@AppRun()
class QGuanRunApplication{

    constructor(){

    }
    run(){
        let _this=this;
      let comm=  qguan("comm")
         let aopContext=new AopContext();
          let context=  ApplicationContext.getInstance();
        context.saveBend('synchro',Synchro) ;
        context.saveBend('dx',Dx) ;
        context.saveBend('rx',Rx) ;
        context.saveBend('phere',Phere) ;
        context.saveBend('block',Block) ;
        context.saveBend('row',Row) ;

        context.saveBend('strTo',StrTo) ;
        context.saveBend('runJsr',new RunJsr()) ;
        context.saveBend('runContext',RunContext) ;
        context.saveBend('runEntity',RunEntity) ;

         context.saveBend('aopContext',aopContext) ;// aop

          context.saveBend('jsrLoad',new JsrLoad()) ;//
          //let aopFactory=new AopFactory();

        let aopFactory=qguan("aopFactory")
          context.saveBend("aopFactory",aopFactory)
          context.saveBend("service",Service);
          context.saveBend("resource",Resource);
          context.saveBend("aop",Aop);
          context.saveBend("runApplication",RunApplication);

          context.saveBend("classLoad",new ClassLoad());
          context.saveBend("funcLoad",new FuncLoad());
        context.saveBend("syncJsLoad",new SyncJsLoad())
        context.saveBend("defaultLoad",new DefaultLoad())
        context.saveBend("preloading",new Preloading())

        context.saveBend("save",new save());
        let root=qguan("root");
        if(root.inBrowser!==null){
            inBrowser =root.inBrowser;
        }
          context.inBrowser=inBrowser;

        let newroot;


        if(  applicationContext.inBrowser){
            newroot = new WebRoot(root.rootPath);
        }else {
            newroot =new NodeRoot(root.rootPath);
        }

        context.saveBend("root",newroot);

        if( applicationContext.inBrowser){
            window.applicationContext=context
            window.qguan=find;
        }else {
            global.applicationContext =context
            global.qguan=find
        }
        debugger
        qguan(comm[0],comm[1],comm[2],comm[3])
        console.log("启动成功...")

    }
}



function find(a,b,c,d){
    if(arguments.length==1||arguments.length==4){
        return applicationContext.find(a,b,c,d);
    }
    let className="";
    let jsrName="";
    let pathName=null
    if(a==0){ //  a==0 表示从自己包里加载
        //console.log((new Error()).stack.split("\n")[2].trim().split(" ")[1])  //获取调用栈的信息
        let coller=  (new Error()).stack.split("\n")[2].trim().split(" ")[1] ;

        let collers= coller.split("_"); //截取报名
        jsrName=collers[1]
    }else {
        jsrName=a
    }

    if(!c){
        className=c;
        pathName=b;
    }else if(b){
        className =b
    }
    return  applicationContext.find(jsrName,pathName,className,'defaultLoad');
}
